/**
 * @Description: 订单列表api
 * @author tao.xie
 * @date 2019-02-25
 */

import ajaxAsync from '../../src/utils/ajaxAsync'
import Order from '../model/Order.js'

async function getOrderList (pageIndex, pageCapacity = 10,filter = 0) {
  let res = await ajaxAsync('/order/list', { PAGE_INDEX: pageIndex, PAGE_CAPACITY: pageCapacity, FILTER: filter})

  let count = res.COUNT
  if (count === 0) {
    return { COUNT: 0 }
  } else {
    let orderList = []
    res.LIST.map(order => {
      orderList.push(new Order(
        order.ORDER_ID,
        order.ORDER_STATE,
        order.COMMENT_STATE,
        order.CREATE_TIME,
        order.GROUP_STATE,
        order.ORDER_TYPE,
        order.STYPE,
        order.GROUP_ID,
        order.STORE_ORDER,
        order.SKUS_FEE,
        order.COUPON_FEE,
        order.POSTAL_FEE,
        order.PAY_FEE,
        order.FINAL_PRICE,
        order.EXPRESS_NO,
        order.EXPRESS_ID,
        order.OP,
        order.TICKET_STATE
      ))
    })

    return { COUNT: count, LIST: orderList }
  }
}

export default getOrderList